package cn.tedu.sp04.service;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp04.fegin.ItemClient;
import cn.tedu.sp04.fegin.UserClient;
import cn.tedu.web.util.JsonResult;
import jdk.internal.instrumentation.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Slf4j
public class OederServiceImpl implements OrderService {
    @Autowired
    private ItemClient itemClient;

    @Autowired
    private UserClient userClient;
    @Override
    public Order getOrders(String orderId) {
        // 远程调用商品，获取商品信息
        JsonResult<List<Item>> items = itemClient.getItem(orderId);
        // 远程调用用户。获取用户信息
        JsonResult<User> user = userClient.getUser(8);

        Order order=new Order();
        order.setId(orderId);
       order.setItems(items.getData());
      order.setUser(user.getData());
        return order;
    }

    @Override
    public void addOrder(Order order) {
        Logger log = null;
        log.info("添加订单,order+ "+order);
   //远程调用商品，减少商品库存
        itemClient.decreaseNumber(order.getItems());
   //远程调用用户，增加用户
        userClient.addScore(order.getUser().getId(), 1000);


    }
}
